﻿<%@ WebHandler Language="C#" Class="ZSAEOSLookBoardHandler" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.SessionState;
using System.IO;
using ReportBusiness;

public class ZSAEOSLookBoardHandler : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private ZSAEOSLookBoardBusiness wp = new ZSAEOSLookBoardBusiness();
    public void ProcessRequest(HttpContext context)
    {
        //获取QCDP指标已维护项
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetItemValue")
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }
            if (context.Request.Form["planyear"] != null)
            {
                para["planyear"] = context.Request.Form["planyear"].ToString();
            }

            DataSet ds = wp.GetQCDPItem(para);

            var json = "";
            json = "{"
                    + "\"Q\":" + JsonConvert.SerializeObject(ds.Tables[0])
                    + ",\"C\":" + JsonConvert.SerializeObject(ds.Tables[1])
                    + ",\"D\":" + JsonConvert.SerializeObject(ds.Tables[2])
                    + ",\"P\":" + JsonConvert.SerializeObject(ds.Tables[3])
                    + "}";

            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //QCDP数据查询
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetItemData")
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }
            if (context.Request.Form["planyear"] != null)
            {
                para["planyear"] = context.Request.Form["planyear"].ToString();
            }
            if (context.Request.Form["planyear"] != null)
            {
                para["zscostitemname"] = context.Request.Form["zscostitemname"].ToString();
            }
            if (context.Request.QueryString["itemtype"] != null)
            {
                para["itemtype"] = context.Request.QueryString["itemtype"].ToString();
            }

            DataSet ds = wp.GetItemData(para);

            var json = "";
            json = "{"
                    + "\"charData\":" + JsonConvert.SerializeObject(ds.Tables[0])
                    + ",\"sumData\":" + JsonConvert.SerializeObject(ds.Tables[1])
                    + "}";

            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //QCDP明细查询
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetItemDetails")
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            //指标项名称
            if (context.Request.Form["zscostitemname"] != null)
            {
                para["zscostitemname"] = context.Request.Form["zscostitemname"].ToString();
            }
            //年份
            if (context.Request.Form["planyear"] != null)
            {
                para["planyear"] = context.Request.Form["planyear"].ToString();
            }
            //月份
            if (context.Request.Form["month"] != null)
            {
                para["month"] = context.Request.Form["month"].ToString().Split('月')[0];
            }
            //分厂
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }
            //指标项类型
            if (context.Request.Form["itemType"] != null)
            {
                para["itemType"] = context.Request.Form["itemType"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = wp.GetItemDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            //json = "{\"rows\":" + json.ToString() + ",\"total\":" + rowCount + "}";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";

            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //S指标柱状图数据查询
        if (context.Request.QueryString["type"] != null && context.Request.QueryString["type"] == "GetSafeBarData")
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            if (context.Request.QueryString["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.QueryString["factoryid"].ToString());
            }

            DataTable dt = wp.GetSafeData(para);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //S指标任务项明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetSafeItemDetails")
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            //分厂
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }
            //指标项类型
            if (context.Request.Form["filter"] != null)
            {
                para["filter"] = context.Request.Form["filter"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = wp.GetSafeItemDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";

            context.Response.Write(json.ToString());
            context.Response.End();
        }
        //S指标问题上报明细
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetSafeProblemDetails")
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            //分厂
            if (context.Request.Form["factoryid"] != null)
            {
                para["factoryid"] = EncryptAndDecryptTool.DesDecrypt(context.Request.Form["factoryid"].ToString());
            }
            //指标项类型
            if (context.Request.Form["filter"] != null)
            {
                para["filter"] = context.Request.Form["filter"].ToString();
            }

            int pageCount = 0;
            int rowCount = 0;

            DataTable dt = wp.GetSafeProblemDetails(para, out pageCount, out rowCount);

            var json = JsonConvert.SerializeObject(dt);
            context.Response.ContentType = "text/json";

            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";

            context.Response.Write(json.ToString());
            context.Response.End();
        }
    }
}